package com.yellowcong.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.websocket.server.ServerEndpoint;

import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.yellowcong.model.User;
import com.yellowcong.service.UserService;

/*
 * 添加用户的配置
 */
@Service
public class UserServiceImpl implements UserService{

	private static Map<String,String> users = new HashMap<>();
	
	//这个地方写得伪代码，其实是需要到数据库里面查询数据的
	static {
		users.put("yellowcong", "yellowcong");
	}
	
	@Override
	public User getUserByName(String username) {
		User user = new User();
		user.setUsername(username);
		user.setPassword(users.get(username));
		return user;
	}

	@Override
	public boolean chkUser(String username, String password) {
		String passwordStr = users.get(username);
		if(StringUtils.isEmpty(password)) {
			return false;
		}
		return password.equals(passwordStr);
	}

}
